package com.bawei.goods.hospital_goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.bawei.goods.hospital_goods.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bawei.goods.hospital_goods.entity.GoodTableEntity;
import com.bawei.goods.hospital_goods.service.GoodTableService;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author doujunxian
 * @email 602137101@gmail.com
 * @date 2021-12-09 18:45:27
 */
@RestController
@RequestMapping("hospital_goods/goodtable")
public class GoodTableController {
    @Autowired
    private GoodTableService goodTableService;



    //上架下架
    @PutMapping("grounding/{id}")
    public R grounding(@PathVariable("id") String id, String status){
        System.out.println("上架");
        return goodTableService.grounding(id,status);
    }

    //图片上传
    @PostMapping("/up/img")
    public String up(MultipartFile file){
        String s = FileUtil.UpFile(file);
        return s;
    }

    /**
     * 修改
     */
    @PutMapping("/update/{id}")
    public R update(String row,@PathVariable("id") String id){
        goodTableService.updateRow(id,row);

        return R.ok();
    }

    /**
     * 列表
     */
    @PostMapping("/list")
        public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodTableService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
        public R info(@PathVariable("id") Integer id){
		GoodTableEntity goodTable = goodTableService.getById(id);

        return R.ok().put("goodTable", goodTable);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
        public R save(@RequestBody GoodTableEntity goodTable){
        String uuid = IdWorker.get32UUID();
        goodTable.setGoodNum(uuid);
		goodTableService.save(goodTable);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
        public R update(@RequestBody GoodTableEntity goodTable){
		goodTableService.updateById(goodTable);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
        public R delete(@RequestBody Integer[] ids){
		goodTableService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
